﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DXApplicationTangche.UC.订单一览新.辅料.service;
using DXApplicationTangche.service;
using DXApplicationTangche.DTO;
using DevExpress.XtraGrid.Demos.util;

namespace DXApplicationTangche.UC.订单一览新.辅料.辅料管理
{
    public partial class XtraUserControl辅料查询 : DevExpress.XtraEditors.XtraUserControl
    {
        public XtraUserControl辅料查询()
        {
            InitializeComponent();
        }
        private void simpleButton刷新_Click(object sender, EventArgs e)
        {
            this.splashScreenManager1.ShowWaitForm();
            this.splashScreenManager1.SetWaitFormCaption("请稍后,正在加载中....");     // 标题
            this.splashScreenManager1.SetWaitFormDescription("正在初始化.....");     // 信息
            显示();
            this.splashScreenManager1.CloseWaitForm();
            
        }
        private void 显示()
        {
            Model辅料一览 model = new Model辅料一览();
            foreach (KeyValuePair<String, List<DTO辅料一览View>> item in model.DTO辅料一览KV)
            {
                if ("AMF".Equals(item.Key))
                {
                    this.gridControlAFM.DataSource = item.Value;
                }
                else if ("baotiao".Equals(item.Key))
                {
                    this.gridControl包条.DataSource = item.Value;
                }
                else if ("chenbu".Equals(item.Key))
                {
                    this.gridControl衬布.DataSource = item.Value;
                }
                else if ("chentiao".Equals(item.Key))
                {
                    this.gridControl衬条.DataSource = item.Value;
                }
                else if ("dianjian".Equals(item.Key))
                {
                    this.gridControl垫肩.DataSource = item.Value;
                }
                else if ("diaozhong".Equals(item.Key))
                {
                    this.gridControl吊钟.DataSource = item.Value;
                }
                else if ("doubu".Equals(item.Key))
                {
                    this.gridControl兜布.DataSource = item.Value;
                }
                else if ("guagou".Equals(item.Key))
                {
                    this.gridControl挂钩.DataSource = item.Value;
                }
                else if ("guasheng".Equals(item.Key))
                {
                    this.gridControl挂绳.DataSource = item.Value;
                }
                else if ("huabian".Equals(item.Key))
                {
                    this.gridControl花边.DataSource = item.Value;
                }
                else if ("kou".Equals(item.Key))
                {
                    this.gridControl扣.DataSource = item.Value;
                }
                else if ("lalian".Equals(item.Key))
                {
                    this.gridControl拉链.DataSource = item.Value;
                }
                else if ("lilian".Equals(item.Key))
                {
                    this.gridControl里料.DataSource = item.Value;
                }
                else if ("lingdiao".Equals(item.Key))
                {
                    this.gridControl领吊.DataSource = item.Value;
                }
                else if ("maobian".Equals(item.Key))
                {
                    this.gridControl毛边.DataSource = item.Value;
                }
                else if ("mianliaobiao".Equals(item.Key))
                {
                    this.gridControl面料标.DataSource = item.Value;
                }
                else if ("peiliao".Equals(item.Key))
                {
                    this.gridControl配料.DataSource = item.Value;
                }
                else if ("pijin".Equals(item.Key))
                {
                    this.gridControl皮筋.DataSource = item.Value;
                }
                else if ("wuyan".Equals(item.Key))
                {
                    this.gridControl乌眼.DataSource = item.Value;
                }
                else if ("xian".Equals(item.Key))
                {
                    this.gridControl线.DataSource = item.Value;
                }
                else if ("yanshengtiao".Equals(item.Key))
                {
                    this.gridControl牙绳条.DataSource = item.Value;
                }
                else if ("yaodaikouhuan".Equals(item.Key))
                {
                    this.gridControl腰带扣环.DataSource = item.Value;
                }
                else if ("yaodaijiandaihuan".Equals(item.Key))
                {
                    this.gridControl腰带肩带环.DataSource = item.Value;
                }
                else if ("zhidai".Equals(item.Key))
                {
                    this.gridControl织带.DataSource = item.Value;
                }
            }
        }
        
    }

    class DTO辅料一览View {
        public String subMaterialType { get; set; }//辅料类别
        public String subMaterialSupplier { get; set; }//供应商
        public String subMaterialNumber { get; set; }//品番（供应商编码）
        public String subMaterialCode { get; set; }//辅料编码
        public String subMaterialName { get; set; }//辅料名称
        public String subMaterialSpecDesc { get; set; }//规格码
        public Image subMaterialPicture { get; set; }//图片

        public DTO辅料一览View(DTO辅料一览 dTO辅料一览) {
            this.subMaterialType = dTO辅料一览.subMaterialType;
            this.subMaterialSupplier = dTO辅料一览.subMaterialSupplier;
            this.subMaterialNumber = dTO辅料一览.subMaterialNumber;
            this.subMaterialCode = dTO辅料一览.subMaterialCode;
            this.subMaterialName = dTO辅料一览.subMaterialName;
            this.subMaterialSpecDesc = dTO辅料一览.subMaterialSpecDesc;
            try
            {
                this.subMaterialPicture
                    = FileService.GetImageByUrl(
                        URL.图片url + URL.辅料图片路径 + dTO辅料一览.subMaterialPicture
                        );
            }
            catch
            {
                this.subMaterialPicture = FunctionHelper.getSSHIRT();
            }
        }
    }

    class Model辅料一览{
        public Dictionary<String, List<DTO辅料一览View>> DTO辅料一览KV { get; set; } = new Dictionary<String, List<DTO辅料一览View>>();
        public List<DTO辅料一览> DTO辅料一览s { get; set; } = new List<DTO辅料一览>();
        /// <summary>
        /// 根据辅料类别显示所以辅料
        /// </summary>
        public Model辅料一览()
        {
            //转换数据为页面显示 
            Dictionary<String, List<DTO辅料一览>> keyValuePairs = 辅料Service.get全辅料一览();
            foreach (KeyValuePair<String, List<DTO辅料一览>> item in keyValuePairs) {
                List<DTO辅料一览View> DTO辅料一览Views = new List<DTO辅料一览View>();
                foreach (DTO辅料一览 DTO辅料一览 in item.Value) {
                    DTO辅料一览Views.Add(new DTO辅料一览View(DTO辅料一览));
                }
                DTO辅料一览KV.Add(
                    item.Key,
                    DTO辅料一览Views
                    );
            }
        }
        /// <summary>
        /// 获取所有辅料，不区分辅料类别
        /// </summary>
        /// <param name="all"></param>
        public Model辅料一览 (Boolean all)
        {
            //获取数据中的全部辅料
            Dictionary<String, List<DTO辅料一览>> keyValuePairs = 辅料Service.get全辅料一览();
            foreach (KeyValuePair<String, List<DTO辅料一览>> item in keyValuePairs)
            {
                DTO辅料一览s.AddRange(item.Value);
            }
        }
    }
}
